home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 16 / sets / setsourc / wordlen.c < prev   
C/C++ Source or Header  |  1989-03-09  |  792b  |  24 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include "sets.h"
  4. /***************************************************************************/
  5.                       unsigned wordlength(void)
  6. /***************************************************************************/
  7. /* This determines the number of bits in a standard unsigned integer. */
  8. {
  9. unsigned x,y;          /* this is standard word length */
  10.  
  11.     x = y = 0;          /* zero all bits */
  12.  
  13.     x = ~x;             /* set all bits to '1' */
  14.  
  15.     do    {
  16.         x = x << 1;     /* shift all bits 1 place to left; fill LSB with '0' */
  17.         y++;            /* count the number of shifts */
  18.     } while(x != 0);    /* when x == 0, all bits have been shifted out */
  19.  
  20.     return y;           /* y == number of bits in word */
  21.  
  22. }  /* end wordlength */
  23.  
  24.